package com.itheima.jobs;


import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.DateUtils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

/**
 * 自定义任务，定时清理垃圾图片
 */
public class ClearSetJob {
    @Autowired
    private OrderSetting orderSetting;
    @Autowired
    private OrderSettingService orderSettingService;

    //清理图片
    public void clearSet() {
        System.out.println("定时清理预约设置");

        try {
            List<String> months = new ArrayList<>();
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.MONTH,-3);//add方法用于计算
            months.add(DateUtils.parseDate2String(calendar.getTime(),"yyyy.MM"));
            //根据月份
            orderSettingService.deleteSetByMonths(months);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
